package com.gisocn.onemap.mvp.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import com.gisocn.onemap.utils.ToastUtil;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/* loaded from: classes.dex */
public abstract class BaseFragment<T extends ViewDataBinding> extends Fragment {
    protected AppCompatActivity mActivity;
    protected Context mContext;
    protected T mViewBinding;
    private View parentView;
    public ProgressDialog progressDialog;
    protected CompositeDisposable mCompositeSubscription = new CompositeDisposable();
    private Handler handler = new Handler(new Handler.Callback() { // from class: com.gisocn.onemap.mvp.base.BaseFragment.1
        @Override // android.os.Handler.Callback
        public boolean handleMessage(Message message) {
            if (message.what == 1352) {
                BaseFragment.this.closeLoadingDialog();
                return false;
            }
            return false;
        }
    });

    protected abstract Object getLayoutId();

    protected abstract void initListener();

    protected abstract void initView();

    protected void addDisposable(Disposable disposable) {
        this.mCompositeSubscription.add(disposable);
    }

    @Override // androidx.fragment.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mActivity = (AppCompatActivity) context;
        this.mContext = context;
    }

    protected Bundle getBundle() {
        if (getArguments() != null) {
            return getArguments();
        }
        return new Bundle();
    }

    public void showToast(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        ToastUtil.show(str);
    }

    public void showProgressDialog(CharSequence charSequence) {
        if (this.mActivity == null) {
            return;
        }
        if (this.progressDialog == null) {
            ProgressDialog progressDialog = new ProgressDialog(this.mActivity);
            this.progressDialog = progressDialog;
            progressDialog.setCanceledOnTouchOutside(false);
        }
        this.progressDialog.setMessage(charSequence);
        this.progressDialog.show();
    }

    public void showProgressDialog() {
        showProgressDialog("数据加载中...");
    }

    public void closeLoadingDialog() {
        ProgressDialog progressDialog;
        if (this.mActivity == null || (progressDialog = this.progressDialog) == null || !progressDialog.isShowing()) {
            return;
        }
        this.progressDialog.dismiss();
    }

    @Override // androidx.fragment.app.Fragment
    public void onPause() {
        super.onPause();
        closeLoadingDialog();
    }

    @Override // androidx.fragment.app.Fragment
    public void onHiddenChanged(boolean z) {
        super.onHiddenChanged(z);
    }

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View view = this.parentView;
        if (view == null) {
            if (getLayoutId() instanceof Integer) {
                this.mViewBinding = (T) DataBindingUtil.inflate(layoutInflater, ((Integer) getLayoutId()).intValue(), viewGroup, false);
            } else if (getLayoutId() instanceof View) {
                this.mViewBinding = (T) DataBindingUtil.findBinding((View) getLayoutId());
            } else {
                throw new ClassCastException("setLayout() must return Integer or View");
            }
            this.parentView = this.mViewBinding.getRoot();
        } else {
            ViewGroup viewGroup2 = (ViewGroup) view.getParent();
            if (viewGroup2 != null) {
                viewGroup2.removeView(this.parentView);
            }
        }
        return this.parentView;
    }

    @Override // androidx.fragment.app.Fragment
    public void onDestroyView() {
        ViewParent parent;
        ViewGroup viewGroup;
        super.onDestroyView();
        View view = this.parentView;
        if (view == null || (parent = view.getParent()) == null || (viewGroup = (ViewGroup) parent) == null || viewGroup.getChildCount() == 0) {
            return;
        }
        viewGroup.removeView(this.parentView);
    }

    @Override // androidx.fragment.app.Fragment
    public void onDestroy() {
        super.onDestroy();
        CompositeDisposable compositeDisposable = this.mCompositeSubscription;
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

    @Override // androidx.fragment.app.Fragment
    public void onViewCreated(View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        initView();
        initListener();
    }
}
